package com.ycp.erp.role.ui.activity;

import android.widget.RelativeLayout;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.one.common.config.RouterPath;
import com.one.common.view.base.BaseActivity;
import com.one.common.view.multitytype.MultiTypeAdapter;
import com.one.common.view.widget.MyTitleBar;
import com.one.common.view.widget.ScrollLinearLayoutManager;
import com.ycp.erp.R;
import com.ycp.erp.role.model.bean.Permissions;
import com.ycp.erp.role.ui.binder.PermissionFBinder;

import java.lang.reflect.Type;
import java.util.ArrayList;

import androidx.recyclerview.widget.RecyclerView;
import butterknife.BindView;

/**
 * Class Des:分配权限
 * Created by bjh on 2021/9/15.
 */
@Route(path = RouterPath.ROLE_DISTRIBUTE_PERMISSION)
public class DistributePermissionActivity extends BaseActivity {
    @BindView(R.id.rlAll)
    RelativeLayout rlAll;
    @BindView(R.id.rcv)
    RecyclerView rcv;
    private String datas="[{\"firstName\":\"采购管理\",\"isSelect\":false,\"permissionsS\":[{\"isSelect\":false,\"secondName\":" +
            "\"采购入库\"},{\"isSelect\":false,\"permissionsTS\":[{\"isSelect\":false,\"thirdName\":\"添加供应商\"},{\"isSelect\":false,\"thirdName\":\"编辑供应商\"}," +
            "{\"isSelect\":false,\"thirdName\":\"供应商详情\"},{\"isSelect\":false,\"thirdName\":\"删除供应商\"}],\"secondName\":\"供应商管理\"}]}," +
            "{\"firstName\":\"销售管理\",\"isSelect\":false,\"permissionsS\":[{\"isSelect\":false,\"secondName\":\"采购入库\"}," +
            "{\"isSelect\":false,\"permissionsTS\":[{\"isSelect\":false,\"thirdName\":\"添加供应商\"},{\"isSelect\":false,\"thirdName\":\"编辑供应商\"}," +
            "{\"isSelect\":false,\"thirdName\":\"供应商详情\"}" +
            ",{\"isSelect\":false,\"thirdName\":\"删除供应商\"}],\"secondName\":\"销售管理\"}]}]";
    @Override
    protected void initPresenter() {

    }
    @Override
    protected void initTitle() {
        super.initTitle();
        getMyTitleBar().setMode(MyTitleBar.Mode.BACK_TITLE)
                .setTitleText("分配权限").hideLine();
    }

    @Override
    public void initData() {
        super.initData();
        ArrayList<Permissions> permissions;
        Gson gson =new Gson();
        Type type =new TypeToken<ArrayList<Permissions>>() {}.getType();
        permissions  = gson.fromJson(datas, type);//data就是2里面的json格式字符串数组

//        Permissions permissions1=new Permissions();
//        permissions1.setFirstName("采购管理");
//        ArrayList<Permissions.PermissionsS> spermissionsS1=new ArrayList<>();
//
//        Permissions.PermissionsS permissionsS1=new Permissions.PermissionsS();
//        permissionsS1.setSecondName("采购入库");
//
//        Permissions.PermissionsS permissionsS2=new Permissions.PermissionsS();
//        permissionsS2.setSecondName("供应商管理");
//        ArrayList<Permissions.PermissionsT> tspermissions2=new ArrayList<>();
//        tspermissions2.add(new Permissions.PermissionsT("添加供应商"));
//        tspermissions2.add(new Permissions.PermissionsT("编辑供应商"));
//        tspermissions2.add(new Permissions.PermissionsT("供应商详情"));
//        tspermissions2.add(new Permissions.PermissionsT("删除供应商"));
//        permissionsS2.setPermissionsTS(tspermissions2);
//        spermissionsS1.add(permissionsS1);
//        spermissionsS1.add(permissionsS2);
//        permissions1.setPermissionsS(spermissionsS1);
//        permissions.add(permissions1);
//
//
//        Permissions permissions2=new Permissions();
//        permissions2.setFirstName("销售管理");
//        ArrayList<Permissions.PermissionsS> spermissionsS2=new ArrayList<>();
//
//        Permissions.PermissionsS permissionsS22=new Permissions.PermissionsS();
//        permissionsS22.setSecondName("采购入库");
//        Permissions.PermissionsS permissionsS23=new Permissions.PermissionsS();
//        permissionsS23.setSecondName("销售管理");
//        ArrayList<Permissions.PermissionsT> tspermissions3=new ArrayList<>();
//        tspermissions3.add(new Permissions.PermissionsT("添加供应商"));
//        tspermissions3.add(new Permissions.PermissionsT("编辑供应商"));
//        tspermissions3.add(new Permissions.PermissionsT("供应商详情"));
//        tspermissions3.add(new Permissions.PermissionsT("删除供应商"));
//        permissionsS23.setPermissionsTS(tspermissions3);
//        spermissionsS2.add(permissionsS22);
//        spermissionsS2.add(permissionsS23);
//        permissions2.setPermissionsS(spermissionsS2);
//        permissions.add(permissions2);
//        Log.e("arrss","arrssarrss");
//        Log.e("arrss",new Gson().toJson(permissions));
        ScrollLinearLayoutManager scrollLinearLayoutManager = new ScrollLinearLayoutManager(mContext);
        scrollLinearLayoutManager.setScrollEnable(true);
        rcv.setLayoutManager(scrollLinearLayoutManager);
        MultiTypeAdapter adapter = new MultiTypeAdapter();
        PermissionFBinder binder = new PermissionFBinder();
        adapter.register(Permissions.class, binder);
        adapter.setItems(permissions);
        rcv.setAdapter(adapter);
    }

    @Override
    public int getLayoutResId() {
        return R.layout.activity_distribute_permission;
    }

}
